package org.example.lease.web.app.controller.region;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.lease.common.result.Result;
import org.example.lease.model.entity.CityInfo;
import org.example.lease.model.entity.DistrictInfo;
import org.example.lease.model.entity.ProvinceInfo;
import org.example.lease.web.app.service.CityInfoService;
import org.example.lease.web.app.service.DistrictInfoService;
import org.example.lease.web.app.service.ProvinceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "地区信息管理")
@RestController
@RequestMapping("/app/region")
public class RegionController {

    @Autowired
    private ProvinceInfoService provinceInfoService;

    @Autowired
    private CityInfoService cityInfoService;

    @Autowired
    private DistrictInfoService districtInfoService;

    @Operation(summary = "查询省份列表")
    @GetMapping("province/list")
    public Result<List<ProvinceInfo>> listProvince(){
        List<ProvinceInfo> provinceInfoList=provinceInfoService.list();
        return Result.ok(provinceInfoList);
    }

    @Operation(summary = "根据省份id查询城市列表")
    @GetMapping("city/list")
    public Result<List<CityInfo>> getCityListByProvinceId(@RequestParam Long provinceId){
        LambdaQueryWrapper<CityInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CityInfo::getProvinceId,provinceId);
        List<CityInfo> list = cityInfoService.list(lambdaQueryWrapper);
        return Result.ok(list);
    }

    @Operation(summary = "根据城市id查询地区列表")
    @GetMapping("district/listByCityId")
    public Result<List<DistrictInfo>> listDistrictInfoByCityId(@RequestParam Long cityId){
        LambdaQueryWrapper<DistrictInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(DistrictInfo::getCityId,cityId);
        List<DistrictInfo> list = districtInfoService.list(lambdaQueryWrapper);
        return Result.ok(list);
    }

}
